﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EShop.Models;

namespace EShop.Controllers
{
    public class HomeController : Controller
    {
        EShopEntities shopDB = new EShopEntities();

        public ActionResult Index()
        {
            // Get most popular albums
            var goods = GetTopSellingGoods(5);

            return View(goods);
        }

        private List<Goods> GetTopSellingGoods(int count)
        {
            // Group the order details by album and return
            // the albums with the highest count

            return shopDB.Goods
                .OrderByDescending(a => a.OrderDetails.Count())
                .Take(count)
                .ToList();
        }

        public ActionResult About()
        {
            ViewBag.Message = "";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "";

            return View();
        }
    }
}
